package com.zyj.springboot.controller;

import com.zyj.springboot.dto.BannerCreateDto;
import com.zyj.springboot.dto.BannerReponseDto;
import com.zyj.springboot.model1.Banner;
import com.zyj.springboot.srevice.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : zhouyajun
 * @date : 2020-05-13
 */

@RestController
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @PostMapping("/v2/banner")
    public BannerReponseDto test(@RequestBody @Validated BannerCreateDto dto){
        BannerReponseDto reponseDto = BannerReponseDto.builder()
                .id(123)
                .name("顶部")
                .pos(2)
                .build();
        return reponseDto;
    }

    @GetMapping("/banner/name/{name}")
    public Banner getBannerByName(@PathVariable String name){
        Banner banner = bannerService.getByName(name);
        return banner;
    }
}
